<template>
	<view class="content">
		<!-- 轮播图 -->
		<swiper
			class="swiper-list"
			autoplay="true"
			indicator-dots="true"
			indicator-active-color="#F70114"
			interval="3000"
			duration="500"
		>
			<template v-for="(item, index) in images">
				<swiper-item class="swiper-item" :key="index" v-if="item && index < 5">
					<image class="image" :src="item" alt="" />
				</swiper-item>
			</template>
		</swiper>

		<!-- 商品信息 -->
		<view class="goods-info">
			<view class="goods-price">
				<view class="deal">
					<view class="end-price">
						<text class="label">券后价</text>¥
						<text class="text">{{ goodsInfo.endPrice | Fixed(2) }}</text>
					</view>
					<block v-for="(perm, index) in permInfo.common" :key="index">
						<view class="subsidy" v-if="perm.name === 'isShelf' && perm.status === 1">
							<text v-if="newGoodsInfo.tljMoney"
								>使用淘礼金¥{{ newGoodsInfo.tljMoney | Fixed(2) }}元</text
							>
							<text v-else>
								<text v-if="options.tljMoney && Number(options.tljMoney) > 0">下单补贴¥{{ options.mdMoney | Fixed(2) }}</text>
								<text v-else>下单补贴¥{{ goodsInfo.allowanceMoney | Fixed(2) }}</text>
							</text>
						</view>
						<view class="community-tlj" v-if="perm.name === 'isShelf' && perm.status === 1 && options.tljMoney && Number(options.tljMoney) > 0">
							<image class="red-back" src="@/static/images/common/red-back.png"></image>
							淘礼金红包{{ options.tljMoney | Fixed(2) }}元
						</view>
					</block>
				</view>
				<view class="original">
					<text class="text">¥{{ goodsInfo.price | Fixed(2) }}</text>
				</view>
			</view>

			<view class="goods-coupon">
				<view class="goods-title">
					<view class="left">
						<image
							mode="widthFix"
							class="icon"
							src="@/static/icons/taobao.png"
							v-if="goodsInfo.shoptype === 0"
						/>
						<image
							mode="widthFix"
							class="icon"
							src="@/static/icons/tmall.png"
							v-if="goodsInfo.shoptype === 1"
						/>
						<image
							mode="widthFix"
							class="icon"
							src="@/static/icons/jd.png"
							v-if="goodsInfo.shoptype === 2"
						/>
						{{ '&nbsp&nbsp&nbsp&nbsp' + goodsInfo.title }}
					</view>
					<view class="right">
						包邮
					</view>
				</view>

				<view class="coupon" @tap="toTaobaoApp">
					<text class="amount">{{ goodsInfo.couponMoney }}元券</text>
					<view class="validity">
						<template v-if="!secondsLeft">
							已过期
						</template>

						<template v-else>
							<count-down
								background-color="#FCE4C5"
								color="#7B6341"
								:day="couponTime[0]"
								:hour="couponTime[1]"
								:minute="couponTime[2]"
								:second="couponTime[3]"
							></count-down>
							{{ couponFlag === 0 ? '开始' : '过期' }}
						</template>
					</view>
				</view>
			</view>
			<view class="shopping-course">
				<image
					class="image"
					mode="widthFix"
					src="@/static/images/goods/course.png"
					alt=""
				/>
				<view class="desc" @tap="$Router.push('/pages/member/help')">
					<text class="iconfont icon-webicon209"></text>
					<text>使用红包和集分宝等抵用会影响补贴专属优惠，查看详情</text>
					<text class="iconfont icon-xiayiye"></text>
				</view>
			</view>
		</view>

		<!-- 店铺信息 -->
		<view class="shop-info">
			<view class="img-box">
				<image
					mode="widthFix"
					class="icon"
					:src="goodsInfo.shopLogo"
					v-if="goodsInfo.shopLogo"
				/>
				<image
					mode="widthFix"
					class="icon"
					src="@/static/icons/taobao.png"
					v-else-if="goodsInfo.shoptype === 0"
				/>
				<image
					mode="widthFix"
					class="icon"
					src="@/static/icons/tmall.png"
					v-else-if="goodsInfo.shoptype === 1"
				/>
				<image
					mode="widthFix"
					class="icon"
					src="@/static/icons/jd.png"
					v-else-if="goodsInfo.shoptype === 2"
				/>
			</view>
			<view class="shop-detail">
				<text class="shop-name">{{ goodsInfo.shopName }}</text>
				<view class="score">
					<template v-if="shopInfo.length > 0">
						<view class="desc" v-for="shop in shopInfo" :key="shop.title">
							{{ shop.title }}
							<text class="text">{{ shop.score }}</text>
						</view>
					</template>

					<template v-else>
						<view class="desc" v-if="goodsInfo.descScore"
							>宝贝描述<text class="text">{{ goodsInfo.descScore }}</text></view
						>
						<view class="desc" v-if="goodsInfo.serviceScore"
							>卖家服务<text class="text">{{ goodsInfo.serviceScore }}</text></view
						>
						<view class="desc" v-if="goodsInfo.shipScore"
							>物流服务<text class="text">{{ goodsInfo.shipScore }}</text></view
						>
					</template>
				</view>
			</view>
		</view>

		<!-- 商品详情 -->
		<view class="simple-detail" v-if="simplePics.length > 0">
			<view class="simple-title">
				<view class="line"></view>
				<text class="text">宝贝详情</text>
				<view class="line"></view>
			</view>
			<view class="simple-images">
				<image
					class="image"
					mode="widthFix"
					:src="item"
					v-for="(item, index) in simplePics"
					:key="index"
				/>
			</view>
		</view>

		<!-- 底部按钮 -->
		<view class="footer-bar">
			<!--回到首页-->
			<view class="back-home" @tap="$Router.pushTab('/pages/index/index')">
				<image class="image" mode="widthFix" src="@/static/icons/shouye.png" />
				<text class="text">首页</text>
			</view>
			<view class="goods-collect" @tap="goodsCollectBtn">
				<image
					v-if="goodsInfo.collected === 1"
					class="image"
					mode="widthFix"
					src="@/static/images/index/icon-collect2.png"
				/>
				<image
					v-else
					class="image"
					mode="widthFix"
					src="@/static/images/index/icon-collect1.png"
				/>
				<text class="text">{{ goodsInfo.collected === 1 ? '取消收藏' : '收藏' }}</text>
			</view>

			<!--按钮组-->
			<view class="btn-group">
				<template v-if="options.type === 'newGoods'">
					<view
						class="button-new"
						@tap="toTaobaoApp"
						:class="[
							{
								disabled:
									newGoodsInfo.surplus === 0 ||
									newGoodsInfo.receiveStatus === 2 ||
									newGoodsInfo.status === 2 ||
									parseFloat(newGoodsInfo.endPrice) -
										parseFloat(newGoodsInfo.tljMoney) !==
										0
							}
						]"
					>
						<text
							v-if="
								newGoodsInfo.surplus === 0 ||
									newGoodsInfo.receiveStatus === 2 ||
									newGoodsInfo.status === 2 ||
									parseFloat(newGoodsInfo.endPrice) -
										parseFloat(newGoodsInfo.tljMoney) !==
										0
							"
							>已抢完</text
						>
						<text v-else>付款即是0元</text>
					</view>
				</template>
				<template v-else>
					<view class="button share" @tap="toShare">
						<text class="title">分享好友</text>
						<block v-for="(perm, index) in permInfo.common" :key="index">
							<text class="text" v-if="perm.name === 'isShelf' && perm.status === 1"
								>赚¥{{ goodsInfo.shareMoney | Fixed(2) }}</text
							>
						</block>
					</view>
					<view class="button coupon" @tap="toTaobaoApp">
						<text class="title">领券购买</text>
						<text class="text"
							>省¥{{
								(Number(goodsInfo.allowanceMoney) + goodsInfo.couponMoney)
									| Fixed(2)
							}}</text
						>
					</view>
				</template>
			</view>
		</view>

		<!--授权弹窗-->
		<authorize ref="authorize"></authorize>

		<!--回到顶部-->
		<view class="scrollTop" :class="[{ show: isShowScrollTop }]" @tap="backTop">
			<text class="iconfont icon-huidaodingbu"></text>
		</view>

		<!--智能搜索-->
		<ai-search ref="aiSearch"></ai-search>

		<!-- 新人免单购买弹窗确认 -->
		<popup ref="newConfirm" class="new-confirm">
			<view class="main">
				<text class="iconfont icon-guanbi" @tap="$refs.newConfirm.close()"></text>
				<view class="title">温馨提示</view>
				<view class="text">
					<view>您确定选择该免单商品？</view>
					<view>一旦选择无法更改哦！</view>
				</view>
				<view class="footer">
					<view class="btn cancel" @tap="$refs.newConfirm.close()">容朕想想</view>
					<view class="btn submit" @tap="submitConfirm()">我已选好</view>
				</view>
			</view>
		</popup>
		
		<!-- 比价订单确认弹窗 -->
		<popup ref="compareOrder" class="compare-order">
			<view class="main">
				<text class="iconfont icon-guanbi" @tap="$refs.compareOrder.close()"></text>
				<view class="title">温馨提示</view>
				
				<template v-for="(perm, index) in permInfo.common">
					<template v-if="perm.name === 'isShelf' && perm.status === 1">
						<view class="text">
							亲亲，为迎合淘宝新规，您找的商品补贴金有所调整，以实际的下单补贴为准！
						</view>
						<view class="text red">
							<view>补贴金为：¥{{ privilege.min_allowanceMoney | Fixed(2) }}</view>
						</view>
						<view class="footer">
							<view class="btn submit" @tap="compareConfirm()">知道了，去抢购</view>
							<text class="text" @tap="toHelp()">如何正确拿补贴呢?</text>
						</view>
					</template>
					<template v-if="perm.name === 'isShelf' && perm.status === 0">
						<view class="text">
							亲亲，为迎合淘宝新规，您找的商品优惠金额有所调整，以实际的下单金额为准！
						</view>
						<view class="text red">
							<view>优惠为：¥{{ privilege.min_allowanceMoney | Fixed(2) }}</view>
						</view>
						<view class="footer">
							<view class="btn submit" @tap="compareConfirm()">知道了，去抢购</view>
							<text class="text" @tap="toHelp()">如何正确拿优惠呢?</text>
						</view>
					</template>
				</template>
			</view>
		</popup>
	</view>
</template>

<script>
const Alibcsdk = uni.requireNativePlugin('UZK-Alibcsdk');
import moment from '@/utils/packges/moment';
import CountDown from '@/components/uni/CountDown';
import Popup from '@/components/uni/Popup';
import Authorize from '@/components/Authorize';
import { mapGetters } from 'vuex';
export default {
	name: 'goods-detail',
	components: {
		CountDown,
		Popup,
		Authorize
	},
	data() {
		return {
			options: {},
			goodsInfo: {},
			images: [],
			secondsLeft: true,
			couponFlag: 1,
			shopInfo: [],
			simplePics: [],
			isShowScrollTop: false,
			couponTime: [], // 优惠券倒计时及时
			newGoodsInfo: {},
			privilege: {}
		};
	},
	onLoad(options) {
		this.options = options;
		this.init();
	},
	onShow() {
		this.$nextTick(() => {
			uni.getClipboardData({
				success: res => {
					if (res.data && this.$store.state.common.aiSearch) {
						this.$refs.aiSearch.open(res.data);
						this.$store.commit({
							type: 'setAiSearch',
							aiSearch: false
						});
					}
				}
			});
		});

		if (uni.getStorageSync('token')) {
			// 获取用户信息
			// #ifdef H5
			this.$store.dispatch('getUserInfo', { versionCode: 140 });
			// #endif
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {
				let params = { ...wgtinfo };
				this.$store.dispatch('getUserInfo', params);
			});
			// #endif
		}
	},
	onHide() {
		this.$refs.aiSearch.close();
	},
	computed: {
		...mapGetters(['userInfo', 'permInfo'])
	},
	methods: {
		// 页面初始化
		init() {
			// 全网商品从缓存中读取详情
			if (this.options.type === 'superGoods') {
				this.goodsInfo = uni.getStorageSync('goodsInfo');
				this.goodsFootpront();

				// 加载轮播图
				if (this.goodsInfo.taobaoImage) {
					this.images = this.goodsInfo.taobaoImage.split(',');
				} else {
					this.images = [this.goodsInfo.pic];
				}
				// 新人首单品读取新的佣金
				if (this.options.isFirstOrder) {
					this.goodsInfo.allowanceMoney = this.options.allowanceMoney;
				}
				// 加载优惠券时间
				this.caluCouponTime(this.goodsInfo.couponStarttime, this.goodsInfo.couponEndtime);

				this.getSimpleDetail(this.goodsInfo.gid);
				this.getShopInfo(this.goodsInfo.gid);
				
				// 自定义统计上报
				let channel;
				if (plus.runtime.channel === 'yyb') {
					channel = '应用宝'
				} else if (plus.runtime.channel === 'vivo') {
					channel = 'vivo应用市场'
				} else if (plus.runtime.channel === 'oppo') {
					channel = 'oppo应用市场'
				} else if (plus.runtime.channel === 'xiaomi') {
					channel = '小米商店'
				} else if (plus.runtime.channel === 'huawei') {
					channel = '华为商店'
				} else {
					channel = '默认渠道'
				}
				uni.report(
					'title',
					'进入超级搜商品详情：' +
						this.goodsInfo.title +
						'-来源：' + channel
				);
			} else if (this.options.type === 'newGoods') {
				// 存储新人商品相关信息
				this.newGoodsInfo = uni.getStorageSync('newGoodsInfo');
				let params = {
					gid: this.options.gid
				};
				this.$service.shopping.goods.detail(params).then(res => {
					this.goodsInfo = res;
					this.goodsFootpront();

					// 加载轮播图
					if (this.goodsInfo.taobaoImage) {
						this.images = this.goodsInfo.taobaoImage.split(',');
					} else {
						this.images = [this.goodsInfo.pic];
					}

					// 加载优惠券时间
					this.caluCouponTime(
						this.goodsInfo.couponStarttime,
						this.goodsInfo.couponEndtime
					);
					
					// 自定义统计上报
					let channel;
					if (plus.runtime.channel === 'yyb') {
						channel = '应用宝'
					} else if (plus.runtime.channel === 'vivo') {
						channel = 'vivo应用市场'
					} else if (plus.runtime.channel === 'oppo') {
						channel = 'oppo应用市场'
					} else if (plus.runtime.channel === 'xiaomi') {
						channel = '小米商店'
					} else if (plus.runtime.channel === 'huawei') {
						channel = '华为商店'
					} else {
						channel = '默认渠道'
					}
					uni.report(
						'title',
						'进入新人专享商品详情：' +
							this.goodsInfo.title +
							'-来源：' + channel
					);
				});

				this.getSimpleDetail(this.options.gid);
				this.getShopInfo(this.options.gid);
			} else {
				let params = {
					gid: this.options.gid
				};
				this.$service.shopping.goods.detail(params).then(res => {
					this.goodsInfo = res;
					this.goodsFootpront();

					// 加载轮播图
					if (this.goodsInfo.taobaoImage) {
						this.images = this.goodsInfo.taobaoImage.split(',');
					} else {
						this.images = [this.goodsInfo.pic];
					}

					// 新人首单品读取新的佣金
					if (this.options.isFirstOrder) {
						this.goodsInfo.allowanceMoney = this.options.allowanceMoney;
					}

					// 加载优惠券时间
					this.caluCouponTime(
						this.goodsInfo.couponStarttime,
						this.goodsInfo.couponEndtime
					);
					
					// 自定义统计上报
					let channel;
					if (plus.runtime.channel === 'yyb') {
						channel = '应用宝'
					} else if (plus.runtime.channel === 'vivo') {
						channel = 'vivo应用市场'
					} else if (plus.runtime.channel === 'oppo') {
						channel = 'oppo应用市场'
					} else if (plus.runtime.channel === 'xiaomi') {
						channel = '小米商店'
					} else if (plus.runtime.channel === 'huawei') {
						channel = '华为商店'
					} else {
						channel = '默认渠道'
					}
					uni.report(
						'title',
						'进入普通商品详情：' +
							this.goodsInfo.title +
							'-来源：' + channel
					);
				});

				this.getSimpleDetail(this.options.gid);
				this.getShopInfo(this.options.gid);
			}
		},
		// 计算优惠券过期时间
		caluCouponTime(couponStarttime, couponEndtime) {
			if (parseInt(couponStarttime) - parseInt(moment().format('X')) > 0) {
				this.couponFlag = 0;
				let endTime = moment(this.goodsInfo.couponStarttime * 1000).format(
					'YYYY-MM-DD HH:mm:ss'
				);
				let startTime = moment().format('YYYY-MM-DD HH:mm:ss');
				let daysLeft = moment(endTime).diff(startTime, 'days');
				let hoursLeft = moment(endTime).diff(startTime, 'hours') - daysLeft * 24;
				let minutesLeft =
					moment(endTime).diff(startTime, 'minutes') -
					daysLeft * 24 * 60 -
					hoursLeft * 60;
				let secondsLeft =
					moment(endTime).diff(startTime, 'seconds') -
					daysLeft * 24 * 60 * 60 -
					hoursLeft * 60 * 60 -
					minutesLeft * 60;
				this.couponTime = [daysLeft, hoursLeft, minutesLeft, secondsLeft];
			} else {
				this.couponFlag = 1;
				let endTime = moment(couponEndtime * 1000).format('YYYY-MM-DD HH:mm:ss');
				let startTime = moment().format('YYYY-MM-DD HH:mm:ss');
				let daysLeft = moment(endTime).diff(startTime, 'days');
				let hoursLeft = moment(endTime).diff(startTime, 'hours') - daysLeft * 24;
				let minutesLeft =
					moment(endTime).diff(startTime, 'minutes') -
					daysLeft * 24 * 60 -
					hoursLeft * 60;
				let secondsLeft =
					moment(endTime).diff(startTime, 'seconds') -
					daysLeft * 24 * 60 * 60 -
					hoursLeft * 60 * 60 -
					minutesLeft * 60;
				if (secondsLeft < 0) {
					this.secondsLeft = false;
				}
				this.couponTime = [daysLeft, hoursLeft, minutesLeft, secondsLeft];
			}
		},
		// 去分享页
		toShare() {
			if (!uni.getStorageSync('token')) {
				uni.navigateTo({
					url: '/pages/common/login',
					animationType: 'slide-in-bottom',
					animationDuration: 300
				});
				return false;
			}
			if (this.userInfo.tbStatus === 1) {
				if (this.options.type === 'superGoods') {
					this.$Router.push({
						path: '/pages/goods/share',
						query: {
							type: 'superGoods',
							title: this.goodsInfo.title
						}
					});
				} else {
					this.$Router.push({
						path: '/pages/goods/share',
						query: {
							gid: this.goodsInfo.gid,
							title: this.goodsInfo.title
						}
					});
				}
			} else {
				if (this.userInfo.tbStatus === 2) {
					uni.showToast({
						title: '亲亲，您的淘宝账号需补充支付宝实名认证信息，请先去认证哦！',
						icon: 'none'
					});
				}
				if (this.userInfo.tbStatus === 3) {
					uni.showToast({
						title: '授权过期，请重新授权',
						icon: 'none'
					});
				}
				this.$refs.authorize.open();
			}
		},
		toTaobaoApp() {
			if (!uni.getStorageSync('token')) {
				uni.navigateTo({
					url: '/pages/common/login',
					animationType: 'slide-in-bottom',
					animationDuration: 300
				});
				return false;
			}
			if (this.userInfo.tbStatus === 1) {
				if (this.options.type === 'newGoods') {
					if (
						(this.newGoodsInfo.surplus === 0 ||
							this.newGoodsInfo.receiveStatus === 2 ||
							this.newGoodsInfo.status === 2 ||
							parseFloat(this.newGoodsInfo.endPrice) -
								parseFloat(this.newGoodsInfo.tljMoney) !==
								0) &&
						this.newGoodsInfo.hasBuy === 0
					) {
						uni.showToast({
							title: '哎呦，商品已抢完啦~',
							icon: 'none'
						});
						return false;
					}

					if (this.newGoodsInfo.hasBuy === 1) {
						uni.showLoading({
							title: '正在打开淘宝...'
						});
						setTimeout(() => {
							uni.hideLoading();
						}, 5000);
						Alibcsdk.init(initResult => {
							if (initResult.status) {
								Alibcsdk.openurl(
									{
										url: this.newGoodsInfo.tkl
									},
									result => {}
								);
							} else {
								uni.showToast({
									title: '初始化失败'
								});
							}
						});
					} else {
						if (this.userInfo.newPerson === 1) {
							this.$refs.newConfirm.open();
						} else {
							this.submitConfirm();
						}
					}
				} else {
					if (Number(this.options.isTljCommunityGood) === 1) {
						// 多联盟分发
						this.$service.shopping.goods.tljCommunityActivity({
							isTljCommunityGood: 1,
							gid: this.options.gid
						}).then(res => {
							if (res.tljBatchId) {
								let params = {
									app: 'hf',
									mdGoodId: this.options.mdGoodId,
									gid: this.goodsInfo.gid,
									type: res.type,
									mdMoney: res.mdMoney,
									tljMoney: res.tljMoney,
									tljBatchId: res.tljBatchId
								};
								console.log(params)

								this.$service.shopping.goods.tljCommunityBuy(params).then(resBuy => {
									console.log(resBuy)
									Alibcsdk.init(
											initResult => {
												if (initResult.status) {
													uni.showLoading({
														title: '正在打开淘宝...'
													})
													setTimeout(() => {
														uni.hideLoading()
													}, 5000)
													Alibcsdk.openurl({
														url: resBuy,
													}, result => {
													});
												} else {
													uni.showToast({
														title: "初始化失败",
														icon: 'none'
													});
												}
											})
								}).catch(err => {
									uni.showToast({
										title: err.message,
										icon: 'none'
									})
								});
							} else {
								uni.showToast({
									title: '该商品已抢完~',
									icon: 'none'
								})
							}
						})
					} else {
						uni.showLoading({
							title: '正在打开淘宝...'
						});
						setTimeout(() => {
							uni.hideLoading()
						}, 5000)
						let params = {
							title: this.goodsInfo.title,
							itemId: this.goodsInfo.gid,
							endPrice: this.goodsInfo.endPrice,
							couponMoney: this.goodsInfo.couponMoney,
							comparison: 1
						};

						// 新人首单补贴订单type为5
						if (this.options.isFirstOrder) {
							params.type = 5;
						}

						this.$service.shopping.taobao.privilege(params).then(res => {
							// 判定为比价订单
							if (Number(res.min_commission_rate) < Number(this.goodsInfo.commissionRate)) {
								this.privilege = res;
								uni.hideLoading();
								this.$refs.compareOrder.open();
							} else {
								Alibcsdk.init(initResult => {
									if (initResult.status) {
										Alibcsdk.openurl(
											{
												url: res.coupon_click_url
											},
											result => {}
										);
									} else {
										uni.showToast({
											title: '初始化失败'
										});
									}
								});
								
								setTimeout(() => {
									uni.hideLoading();
								}, 2000);
							}
						});
					}
				}
			} else {
				if (this.userInfo.tbStatus === 2) {
					uni.showToast({
						title: '亲亲，您的淘宝账号需补充支付宝实名认证信息，请先去认证哦！',
						icon: 'none'
					});
				}
				if (this.userInfo.tbStatus === 3) {
					uni.showToast({
						title: '授权过期，请重新授权',
						icon: 'none'
					});
				}
				// 开启授权弹窗
				this.$refs.authorize.open();
			}
		},
		// 确认新人购买
		submitConfirm() {
			uni.showLoading({
				title: '正在打开淘宝...'
			});
			setTimeout(() => {
				uni.hideLoading();
			}, 5000);
			let params = {
				...this.newGoodsInfo
			};
			this.$service.shopping.goods
				.newPersonBuy(params)
				.then(resBuy => {
					Alibcsdk.init(initResult => {
						if (initResult.status) {
							Alibcsdk.openurl(
								{
									url: resBuy
								},
								result => {}
							);
						} else {
							uni.showToast({
								title: '初始化失败',
								icon: 'none'
							});
						}
					});
				})
				.catch(error => {
					uni.showToast({
						title: error.message,
						icon: 'none'
					});
				});
			this.$refs.newConfirm.close();
		},
		// 获取店铺信息
		getShopInfo(gid) {
			uni.request({
				url:
					'https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data={%22itemNumId%22%3A%22' +
					gid +
					'%22}',
				success: res => {
					this.shopInfo = res.data.data.seller.evaluates;
				}
			});
		},
		// 获取详细大图
		getSimpleDetail(gid) {
			uni.request({
				url: encodeURI(
					'https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdesc/6.0/?&timeout=2000&data={"id":"' +
						gid +
						'","type":"0","f":"TB12ekTu4n1gK0jSZKP8qtvUXla"}'
				),
				success: res => {
					if (res.data.data.wdescContent.pages.length > 0) {
						let simplePics = [];
						res.data.data.wdescContent.pages.forEach(item => {
							let url = item.match(/\/\/img.alicdn([^\<]*)\.jpg/);
							if (url !== null) {
								url = unescape(url[0]);
								if (url) {
									simplePics.push('https:' + url);
								}
							}
						});
						this.simplePics = simplePics;
					} else {
						this.simplePics = [];
					}
				}
			});
		},
		// 回到顶部
		backTop() {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 0
			});
		},
		// 商品收藏
		goodsCollectBtn() {
			if (!uni.getStorageSync('token')) {
				uni.navigateTo({
					url: '/pages/common/login',
					animationType: 'slide-in-bottom',
					animationDuration: 300
				});
				return false;
			}
			let type = 0;
			if (this.goodsInfo.collected == 0) {
				type = 1;
			} else if (this.goodsInfo.collected == 1) {
				type = 0;
			}

			this.goodsCollect(type);
		},
		// 商品足迹
		goodsFootpront() {
			if (uni.getStorageSync('token')) {
				this.goodsCollect(3);
			}
		},
		// 商品收藏
		goodsCollect(type) {
			let superGoods = 0;
			if (this.options.type) {
				superGoods = 1;
			} else {
				superGoods = 0;
			}
			let {
				gid,
				title,
				allowanceMoney,
				shortTitle,
				desc,
				pic,
				price,
				shoptype,
				link,
				sellerId,
				sale,
				shopName,
				taobaoImage,
				detailPics,
				startTime,
				couponConditions,
				couponReceive,
				couponNum,
				couponStarttime,
				couponEndtime,
				couponMoney,
				commissionType,
				commissionRate,
				couponUrl,
				endPrice,
				shareMoney
			} = this.goodsInfo;

			this.$service.collectedGoods.goods
				.traceGoods({
					gid,
					collected: type,
					title,
					allowanceMoney,
					shortTitle,
					desc,
					pic,
					price,
					shoptype,
					link,
					sellerId,
					sale,
					shopName,
					taobaoImage,
					detailPics,
					startTime,
					couponConditions,
					couponReceive,
					couponNum,
					couponStarttime,
					couponEndtime,
					couponMoney,
					commissionType,
					commissionRate,
					couponUrl,
					endPrice,
					superGoods,
					shareMoney
				})
				.then(res => {
					if (type == 0) {
						uni.showToast({
							title: '已取消',
							icon: 'none'
						});
						this.goodsInfo.collected = 0;
					} else if (type == 1) {
						uni.showToast({
							title: '收藏成功',
							icon: 'none'
						});
						this.goodsInfo.collected = 1;
					}
				})
				.catch(err => {
					uni.showToast({
						title: err.message,
						icon: 'none'
					});
				});
		},
		// 比价订单确认购买
		compareConfirm() {
			Alibcsdk.init(initResult => {
				if (initResult.status) {
					Alibcsdk.openurl(
						{
							url: this.privilege.coupon_click_url
						},
						result => {}
					);
				} else {
					uni.showToast({
						title: '初始化失败'
					});
				}
			});
			this.$refs.compareOrder.close()
		},
		toHelp() {
			this.$Router.push({
				path: '/pages/member/help',
				query: {
					name: '联盟新规'
				}
			})
		}
	},
	onPageScroll(e) {
		if (e.scrollTop > 350) {
			this.isShowScrollTop = true;
		} else {
			this.isShowScrollTop = false;
		}
	}
};
</script>

<style lang="scss" scope>
.content {
	padding-bottom: 128rpx;

	.swiper-list {
		width: 750rpx;
		height: 750rpx;

		.swiper-item {
			.image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.goods-info {
		.goods-price {
			height: 110rpx;
			background: linear-gradient(225deg, #f76a11, $main-color);
			color: $color-white;
			padding: 18rpx 34rpx;
			@include flexBox(center, null, column);

			.deal {
				font-size: 32rpx;
				@include flexBox(null, center);

				.end-price {
					.label {
						font-size: 26rpx;
					}
					.text {
						font-size: 46rpx;
						font-weight: 600;
					}
				}
				
				.subsidy {
					margin-left: 20rpx;
					background: #fbe4c5;
					border-radius: 8rpx;
					color: $main-color;
					padding: 4rpx 10rpx;
					font-size: 24rpx;
				}

				.community-tlj {
					margin-left: 20rpx;
					color: #FF0014;
					border-radius: 8rpx;
					background: #FFF0ED;
					padding: 4rpx 10rpx;
					font-size: 24rpx;
					@include flexBox(center, center);
					.red-back {
						width: 23rpx;
						height: 26rpx;
						margin-right: 4rpx;
					}
				}
			}

			.original {
				.text {
					font-size: 28rpx;
					text-decoration: line-through;
					color: #ffd8d8;
				}
			}
		}

		.goods-coupon {
			padding: 16rpx 10rpx;
			background: $color-white;
			.goods-title {
				@include flexBox(space-between, flex-start) .left {
					font-size: 28rpx;
					color: #3a3a3a;
					position: relative;
					@include ellipsis(2);
					.icon {
						position: absolute;
						width: 30rpx;
						height: 30rpx;
						top: 6rpx;
					}
				}
				.right {
					color: #717076;
					font-size: 24rpx;
					width: 84rpx;
					min-width: 84rpx;
					background: $main-color;
					color: #fff;
					border-radius: 8rpx;
					@include flexBox(center, center);
				}
			}

			.coupon {
				width: 616rpx;
				height: 152rpx;
				background: url('../../static/images/goods/coupon.png') no-repeat center center;
				background-size: 100% 100%;
				margin: 20rpx auto;
				transition: 0.5s;
				@include flexBox(null, center);

				.amount {
					color: $main-color;
					font-size: 36rpx;
					width: 180rpx;
					margin-left: 10rpx;
					text-align: center;
				}

				.validity {
					color: #7b6341;
					font-size: 24rpx;
					width: 250rpx;
					margin-left: -10rpx;
					@include flexBox(center);
				}

				&:hover,
				&:focus,
				&:active {
					transform: scale(1.05);
				}
			}
		}

		.shopping-course {
			width: 100%;

			.image {
				width: 100%;
				height: 168rpx;
				display: block;
			}

			.desc {
				font-size: 22rpx;
				color: #6f4a43;
				width: 100%;
				height: 40rpx;
				background: #ffebe6;
				@include flexBox(center, center);

				.icon-webicon209 {
					font-size: 36rpx;
					margin-right: 4rpx;
					height: 40rpx;
					@include flexBox(center, center);
				}

				.icon-xiayiye {
					margin-left: 10rpx;
					font-size: 26rpx;
				}
			}
		}
	}

	.shop-info {
		display: flex;
		padding: 34rpx;
		background: $color-white;
		margin-top: 10rpx;

		.img-box {
			width: 92rpx;
			height: 92rpx;
			border-radius: 16rpx;
			overflow: hidden;
			@include flexBox(center, center);

			.image {
				max-width: 100%;
				max-height: 100%;
			}
		}

		.shop-detail {
			margin-left: 20rpx;
			color: $text-black;
			font-size: 28rpx;
			flex: 1;
			@include flexBox(space-around, null, column);

			.shop-name {
				font-weight: 600;
			}

			.score {
				display: flex;

				.desc {
					margin-right: 20rpx;

					.text {
						color: $color-red;
						margin-left: 4rpx;
					}
				}
			}
		}
	}

	.simple-detail {
		.simple-title {
			@include flexBox(center, center);

			.text {
				color: #8d8d8d;
				margin: 20rpx;
				font-size: 28rpx;
			}

			.line {
				width: 70rpx;
				height: 2rpx;
				background: #c6c6c6;
			}
		}

		.simple-images {
			width: 100%;

			.image {
				width: 100%;
				display: block;
			}
		}
	}

	.footer-bar {
		width: 100%;
		padding: 20rpx 10rpx;
		background: $color-white;
		position: fixed;
		bottom: 0;
		box-shadow: 0 0 12rpx #ccc;
		box-sizing: border-box;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		@include flexBox(space-between);

		.back-home {
			width: 100rpx;
			margin-bottom: 20rpx;
			@include flexBox(null, center, column);

			.image {
				width: 40rpx;
				height: 37rpx;
			}

			.text {
				font-size: 20rpx;
				color: #242348;
			}
		}
		.goods-collect {
			@include flexBox(null, center, column);
			color: #242348;
			font-size: 20rpx;
			margin-bottom: 20rpx;
			margin-right: 10rpx;
			.image {
				width: 38rpx;
				height: 36rpx;
			}
		}

		.btn-group {
			border-radius: 50rpx;
			overflow: hidden;
			display: flex;
			margin-bottom: 20rpx;

			.button-new {
				width: 520rpx;
				line-height: 80rpx;
				color: $color-white;
				background: $main-color;
				text-align: center;
				font-size: 32rpx;
				&.disabled {
					background: #ccc;
				}
			}

			.button {
				width: 256rpx;
				height: 80rpx;
				color: $color-white;
				@include flexBox(center, center, column);
				.title {
					font-size: 28rpx;
					font-weight: 400;
				}

				.text {
					font-size: 22rpx;
				}

				&.share {
					background: #29231e;
				}

				&.coupon {
					background: #29231e;
					background: linear-gradient(225deg, #f77301, $main-color);
				}
			}
		}
	}
}
.new-confirm {
	.main {
		position: relative;
		padding: 30rpx;
		background: #fff;
		border-radius: 16rpx;
		width: 600rpx;
		.icon-guanbi {
			position: absolute;
			right: 30rpx;
			top: 20rpx;
			font-size: 40rpx;
			color: #d9d9d9;
		}
		.title {
			text-align: center;
			font-size: 32rpx;
			color: #383434;
			font-weight: 600;
		}
		.text {
			font-size: 32rpx;
			color: $main-color;
			text-align: center;
			margin: 44rpx;
		}
		.footer {
			@include flexBox(space-around, center);
			.btn {
				width: 184rpx;
				line-height: 64rpx;
				text-align: center;
				border-radius: 50rpx;
				font-size: 28rpx;
				&.cancel {
					background: #d9d9d9;
					color: #717076;
				}
				&.submit {
					background: $main-color;
					color: #fff;
				}
			}
		}
	}
}
.compare-order {
	.main {
		position: relative;
		padding: 30rpx;
		background: #fff;
		border-radius: 16rpx;
		width: 600rpx;
		.icon-guanbi {
			position: absolute;
			right: 30rpx;
			top: 20rpx;
			font-size: 40rpx;
			color: #d9d9d9;
		}
		.title {
			text-align: center;
			font-size: 32rpx;
			color: #383434;
			font-weight: 600;
		}
		.text {
			font-size: 28rpx;
			color: #1E1E1E;
			text-align: left;
			margin: 30rpx 12rpx;
			line-height: 48rpx;
		}
		.red {
			font-size: 32rpx;
			color: $main-color;
			text-align: center;
			font-weight: 600;
			margin-bottom: 40rpx;
		}
		.footer {
			@include flexBox(space-around, center, column);
			.btn {
				line-height: 68rpx;
				text-align: center;
				border-radius: 50rpx;
				font-size: 28rpx;
				padding: 0 38rpx;
				&.submit {
					background: $main-color;
					color: #fff;
				}
			}
			.text {
				color: #717076;
				margin: 26rpx 0 10rpx;
			}
		}
	}
}
</style>
